<template>
  <div class="home-header">
    <img src="@/assets/logo.png">
    <van-dropdown-menu>
      <van-dropdown-item :modelValue="category" :options="options" @change="change" />
    </van-dropdown-menu>
  </div>
</template>
<script lang="ts">
import { CATEGORY_TYPES } from '@/typings/home';
import { defineComponent, PropType, reactive, toRefs } from 'vue';

export default defineComponent({
  props: {
    category: {
      type: Number as PropType<CATEGORY_TYPES>,
    },
  },

  emits: ['setCurrentCategory'], // 为了提示作用的
  setup(props, context) {
    // props.category;
    // context.emit('setCurrentCategory');

    let state = reactive({
      options: [
        { text: '全部课程', value: CATEGORY_TYPES.ALL },
        { text: 'react课程', value: CATEGORY_TYPES.REACT },
        { text: 'vue课程', value: CATEGORY_TYPES.VUE },
        { text: 'node课程', value: CATEGORY_TYPES.NODE },
      ],
    });

    function change(value: CATEGORY_TYPES) {
      context.emit('setCurrentCategory', value);
    }

    return {
      ...toRefs(state),
      change,
    };
  },
});
</script>
<style lang='scss'>
.home-header {
  height: 65px;
  background-color: #2a2a2a;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 2.5%;
  position: fixed;
  top: 0;
  left: 0;
  width: 90%;
  img {
    height: 50px;
  }
  .van-dropdown-menu__item {
    background-color: #2a2a2a;
  }
  .van-dropdown-menu__title {
    color: white;
  }
}
</style>